﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TSVNAddin.TSVN;
using Rhino.Mocks;
using TSVNAddin.Config;
using EnvDTE;
using TSVNAddin.SVN;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class DiffCommandFixture
	{
		[Test]
		public void ShouldInvokeExecuteTortoiseProcExecutorWithDiffParamWhenExecCalled()
		{
			var document = MockRepository.GenerateMock<ActiveDocumentAdapter>((Document)null);
			document.Stub(x => x.GetFileName()).Return(@"c:\svn\pippo.txt");

			var executor = MockRepository.GenerateMock<TortoiseProcExecutor>((ProcessStarter)null, (ConfigStorage)null);
			executor.Expect(x => x.Exec(TortoiseProcCommandType.Diff, @"c:\svn\pippo.txt"));

			DiffCommand command = new DiffCommand(document, executor, null);
			command.Execute();

			executor.VerifyAllExpectations();
		}

		[Test]
		public void OnQueryStatusShouldReturnVisibleAndEnabledWhenActiveDocumentIsVersionable()
		{
			var document = MockRepository.GenerateMock<ActiveDocumentAdapter>((Document)null);
			document.Stub(x => x.IsVersionable()).Return(true);
			document.Stub(x => x.GetFileName()).Return(@"c:\svn\pippo.txt");

			var repository = MockRepository.GenerateMock<Repository>((SolutionAdapter)null, null);
			repository.Expect(x => x.Contains(@"c:\svn\pippo.txt")).Return(true);

			DiffCommand command = new DiffCommand(document, null, repository);
			CommandStatus status = command.QueryStatus();

			Assert.AreEqual(CommandStatus.VisibleAndEnabled, status);
		}

		[Test]
		public void OnQueryStatusShouldReturnVisibleAndDisabledWhenActiveDocumentIsNotVersionable()
		{
			var document = MockRepository.GenerateMock<ActiveDocumentAdapter>((Document)null);
			document.Stub(x => x.IsVersionable()).Return(false);

			DiffCommand command = new DiffCommand(document, null, null);
			CommandStatus status = command.QueryStatus();

			Assert.AreEqual(CommandStatus.VisibleAndDisabled, status);
		}

		[Test]
		public void OnQueryStatusShouldReturnVisibleAndDisabledWhenActiveDocumentIsNotLinkedToWorkingRoot()
		{
			var document = MockRepository.GenerateMock<ActiveDocumentAdapter>((Document)null);
			document.Stub(x => x.IsVersionable()).Return(true);
			document.Stub(x => x.GetFileName()).Return(@"c:\svn\pippo.txt");

			var repository = MockRepository.GenerateMock<Repository>((SolutionAdapter)null, null);
			repository.Expect(x => x.Contains(@"c:\svn\pippo.txt")).Return(false);

			DiffCommand command = new DiffCommand(document, null, repository);
			CommandStatus status = command.QueryStatus();

			Assert.AreEqual(CommandStatus.VisibleAndDisabled, status);

			repository.VerifyAllExpectations();
		}
	}
}
